import 'package:freezed_annotation/freezed_annotation.dart';
import 'dart:convert';

part 'index_get_goodslist_response.freezed.dart';
part 'index_get_goodslist_response.g.dart';

@freezed
class IndexGetGoodslistResponse with _$IndexGetGoodslistResponse {
  const factory IndexGetGoodslistResponse({
    @JsonKey(name: "code") required int code,
    @JsonKey(name: "msg") required String msg,
    @JsonKey(name: "time") required int time,
    @JsonKey(name: "data") required Data data,
  }) = _IndexGetGoodslistResponse;

  factory IndexGetGoodslistResponse.fromJson(Map<String, dynamic> json) =>
      _$IndexGetGoodslistResponseFromJson(json);
}

@freezed
class Data with _$Data {
  const factory Data({
    @JsonKey(name: "total") required int total,
    @JsonKey(name: "per_page") required int perPage,
    @JsonKey(name: "current_page") required int currentPage,
    @JsonKey(name: "last_page") required int lastPage,
    @JsonKey(name: "data") required List<Datum> data,
  }) = _Data;

  factory Data.fromJson(Map<String, dynamic> json) => _$DataFromJson(json);
}

@freezed
class Datum with _$Datum {
  const factory Datum({
    @JsonKey(name: "id") required int id,
    @JsonKey(name: "user_id") required int userId,
    @JsonKey(name: "mainImage") required List<String> mainImage,
    @JsonKey(name: "date") required DateTime date,
    @JsonKey(name: "cate_id") required int cateId,
    @JsonKey(name: "userAvatar") required String userAvatar,
    @JsonKey(name: "userName") required UserName userName,
    @JsonKey(name: "content") required String content,
    @JsonKey(name: "collectionCount") required int collectionCount,
    @JsonKey(name: "commentCount") required int commentCount,
    @JsonKey(name: "likeCount") required int likeCount,
    @JsonKey(name: "is_sh") required int isSh,
    @JsonKey(name: "is_ding") required int isDing,
    @JsonKey(name: "is_tuijian") required int isTuijian,
    @JsonKey(name: "lv") required int lv,
    @JsonKey(name: "viewUser") required ViewUser viewUser,
    @JsonKey(name: "medal_list") required List<dynamic> medalList,
    @JsonKey(name: "ziji") required int ziji,
    @JsonKey(name: "manage") required int manage,
    @JsonKey(name: "label") required List<dynamic> label,
  }) = _Datum;

  factory Datum.fromJson(Map<String, dynamic> json) => _$DatumFromJson(json);
}

enum UserName {
  @JsonValue("匿名")
  EMPTY
}

final userNameValues = EnumValues({"匿名": UserName.EMPTY});

@freezed
class ViewUser with _$ViewUser {
  const factory ViewUser({
    @JsonKey(name: "latestUserAvatar") required List<dynamic> latestUserAvatar,
    @JsonKey(name: "viewUserCount") required int viewUserCount,
  }) = _ViewUser;

  factory ViewUser.fromJson(Map<String, dynamic> json) =>
      _$ViewUserFromJson(json);
}

class EnumValues<T> {
  Map<String, T> map;
  late Map<T, String> reverseMap;

  EnumValues(this.map);

  Map<T, String> get reverse {
    reverseMap = map.map((k, v) => MapEntry(v, k));
    return reverseMap;
  }
}
